package org.supereasymock.examples;

import org.supereasymock.SuperEasyMock._

object Simple {
    implicit val context = new SuperEasyMockContext
    
    def main(args: Array[String]) {
        simple1()
        simple2()
    }
    
    def simple1() {
        val mockList = createStrictMock(classOf[java.util.List[String]])
        
        expect {
            mockList.get(0) andReturn "Hello"
            mockList.clear() times 2
            mockList.isEmpty() andReturn true
        } test {
            mockList.get(0)
            mockList.clear()
            mockList.clear()
            mockList.isEmpty()
        } verify {
            println("optional verify")
        }
    }
    
    def simple2() {
        val mockList = createStrictMock(classOf[java.util.List[String]])	
        
        expect {
            mockList.add("World!") andReturn true
            mockList.get(1) andThrow new IndexOutOfBoundsException
            mockList.get(0) andReturn "World!"
        } test {
            mockList.add("World!")
            try {
                mockList.get(1)
            } catch {
                case e: IndexOutOfBoundsException => println("caught")
            }
            mockList.get(0)
        }
    }
    
}
